package com.tsingteng.cosfun.ui.message.geneal.presenter;

import android.util.Log;

import com.tsingteng.cosfun.bean.FollowBean;
import com.tsingteng.cosfun.bean.ParagraphComment;
import com.tsingteng.cosfun.bean.PlayCommont;
import com.tsingteng.cosfun.bean.PlayDetailsBean;
import com.tsingteng.cosfun.bean.PullBlackBean;
import com.tsingteng.cosfun.callback.RxObserver;
import com.tsingteng.cosfun.http.RxSchedulers;
import com.tsingteng.cosfun.mvp.presenter.BasePresenter;
import com.tsingteng.cosfun.ui.message.geneal.model.PlayModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 描述 :
 * 创建人: 肖利.
 * 时间:2018/8/6
 * qq(872179966)
 */

public class PlayDetailsPresenter extends BasePresenter<PlayDetailsContract.IPlayDetailsView> implements PlayDetailsContract.IPlayDetailsPresenter{
    private PlayDetailsContract.IPlayDetailsView mView;
    private PlayModel mModel;

    public PlayDetailsPresenter() {
        this.mModel = new PlayModel();
    }

    @Override
    public void getPlayDetailData(String paragraphId) {
        mView = getView();
        RxObserver<PlayDetailsBean> rxObserver = new RxObserver<PlayDetailsBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                mView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(PlayDetailsBean playDetailsBean) {
                mView.showPlayDetailsData(playDetailsBean);
            }
        };

        mModel.getPlayDetails(paragraphId,rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void getPlayDetailCommontListData(String paragraphId, int currentPage, int count) {
        mView= getView();
        RxObserver<PlayCommont> rxObserver = new RxObserver<PlayCommont>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                mView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(PlayCommont playCommont) {
                mView.showPlayDetailCommontListData(playCommont);
            }
        };
        mModel.getPlayDetailsCommontList(paragraphId,String.valueOf(currentPage),String.valueOf(count),rxObserver);
        addDisposable(rxObserver);

    }

    @Override
    public void getDelPlay(String paragraph_id) {
        mView= getView();
        RxObserver<String> rxObserver = new RxObserver<String>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                mView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(String s) {
                mView.showDelResult(s);
            }
        };

        mModel.getDelPlay(paragraph_id,rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void getAddNotLikePlay(String paragraph_id) {
        mView= getView();
        RxObserver<String> rxObserver = new RxObserver<String>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                mView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(String s) {
                mView.ShowNotLiketResult(s);
            }
        };

        mModel.getAddNotLikePlay(paragraph_id,rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void getAddPlayComment(String paragraph_id, String comment_type, String content, String comment_object_id) {
        mView= getView();
        RxObserver<ParagraphComment> rxObserver = new RxObserver<ParagraphComment>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                if (errorCode == 50072 ||errorCode == 50073) {
                    mView.showDialog(errorCode);
                }else {
                    mView.showFail(errorMsg);
                }
            }

            @Override
            protected void onSuccess(ParagraphComment data) {
                mView.showAddCommentResult(data);
            }
        };

        mModel.getAddPlayComment(paragraph_id,comment_type,content,comment_object_id,rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void loginFollowFans(String follow_id) {
        mView = getView();
        RxObserver<FollowBean> rxObserver = new RxObserver<FollowBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
            }

            @Override
            protected void onSuccess(FollowBean followBean) {
                mView.getFollowResult(followBean);
            }
        };

        mModel.getFollowNotification(follow_id,rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void loginNoFollow(String follow_id) {
        mView = getView();
        RxObserver<FollowBean> rxObserver = new RxObserver<FollowBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                Log.e("ERROR",errorMsg);
            }

            @Override
            protected void onSuccess(FollowBean followBean) {
                mView.getFollowResult(followBean);
            }
        };

        mModel.getNoFollowNotification(follow_id,rxObserver);
        addDisposable(rxObserver);
    }

    @Override
    public void getPraiseOrNotData(String praise_type, String id, String type) {
        mView = getView();
        RxObserver<Integer> rxObserver = new RxObserver<Integer>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                mView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(Integer data) {
                mView.showPraiseResult(data);
            }
        };
        mModel.getPraiseOrNot(praise_type,id,type,rxObserver);
        addDisposable(rxObserver);
    }
    @Override
    public void getCancelPullBlack(long user_id) {
        mView = getView();
        Callback<PullBlackBean> workCallback = new Callback<PullBlackBean>() {
            @Override
            public void onResponse(Call<PullBlackBean> call, Response<PullBlackBean> response) {
                PullBlackBean body = response.body();
                int data = body.getData();
                mView.showCancelPullBlack(data);
            }

            @Override
            public void onFailure(Call<PullBlackBean> call, Throwable t) {
                Log.e("/////", t.getMessage());
            }
        };
        mModel.getCancelPullBlackInfo(user_id, workCallback);
    }
}
